package com.zhanglu.fun.services.authentication.login;

import com.zhanglu.fun.services.authentication.bean.IsLogin;
import com.zhanglu.fun.services.authentication.bean.User;
import com.zhanglu.fun.services.authentication.bean.UserResponse;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhanglu
 * @description
 * @date 2017/8/28 20:14
 */
@RestController
@Slf4j
public class LoginRouter {

    @Autowired
    private LoginService loginService;

    @ApiOperation(value = "登录", notes = "根据帐号密码进行登录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "username", value = "用户帐号", required = true, dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "password", value = "用户密码", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = UserResponse.class) })
    @GetMapping("/fun/login")
    public UserResponse login(@RequestParam("username") String username, @RequestParam("password") String password) {
        return loginService.login(username, password);
    }

    @ApiOperation(value = "是否登录", notes = "根据帐号判断用户是否登录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = boolean.class) })
    @GetMapping("/fun/login/token")
    public IsLogin isLogin(@RequestParam("token") String token) {
        return loginService.isLogin(token);
    }
}
